package com.ymatou.iapi.godfreightmgr.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.DeleteCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.service.DeleteCollectionGoodsAddressCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.CollectiongoodsAddress;
/**
*删除自提点
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteCollectionGoodsAddress{
	private static DeleteCollectionGoodsAddressBean deletecollectiongoodsaddressBean;
	private static DeleteCollectionGoodsAddressCall deletecollectiongoodsaddressCall;
	com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper CollectionGoodsWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除自提点");
	}

	@Before
	public void caseUp() {
		deletecollectiongoodsaddressBean=new DeleteCollectionGoodsAddressBean();
		deletecollectiongoodsaddressCall=new DeleteCollectionGoodsAddressCall();
		CollectionGoodsWapper=new com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletecollectiongoodsaddressCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_001() {
		Logger.start(true,"删除自提点成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			createcollectiongoodsaddressBean.setAddressName("add2");
			int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			deletecollectiongoodsaddressBean.setAddressId(addressId);
			deletecollectiongoodsaddressBean.setSellerId(mchId_channl);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("200", deletecollectiongoodsaddressCall.getString("code"), "验证code");
			CollectiongoodsAddress c = CollectionGoodsWapper.selectCollectiongoodsAddress(addressId, mchId_channl).get(0);
			Logger.verifyEquals(true, c.getDeleted(), "删除");
			CollectiongoodsAddress c2 = CollectionGoodsWapper.selectCollectiongoodsAddress(addressId2, mchId_channl).get(0);
			Logger.verifyEquals(false, c2.getDeleted(), "不删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_002() {
		Logger.start(true,"不输入sellerid失败");
		try {
			deletecollectiongoodsaddressBean.setAddressId(1);
//			deletecollectiongoodsaddressBean.setSellerId(1);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("400", deletecollectiongoodsaddressCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_003() {
		Logger.start(true,"不输入addressid失败");
		try {
			deletecollectiongoodsaddressBean.setSellerId(1);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("400", deletecollectiongoodsaddressCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_004() {
		Logger.start(true,"输入addressid和sellerid不匹配失败");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			createcollectiongoodsaddressBean.setAddressName("add2");
			int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			deletecollectiongoodsaddressBean.setAddressId(addressId-1);
			deletecollectiongoodsaddressBean.setSellerId(mchId_channl);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("400", deletecollectiongoodsaddressCall.getString("code"), "验证code");
			CollectiongoodsAddress c = CollectionGoodsWapper.selectCollectiongoodsAddress(addressId-1, null).get(0);
			Logger.verifyEquals(false, c.getDeleted(), "删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_005() {
		Logger.start(true,"自提开关开启时最后一个自提点不能删除");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			deletecollectiongoodsaddressBean.setAddressId(addressId);
			deletecollectiongoodsaddressBean.setSellerId(mchId_channl);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("400", deletecollectiongoodsaddressCall.getString("code"), "验证code");
			CollectiongoodsAddress c = CollectionGoodsWapper.selectCollectiongoodsAddress(addressId, mchId_channl).get(0);
			Logger.verifyEquals(false, c.getDeleted(), "不删除");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteCollectionGoodsAddress_006() {
		Logger.start(true,"自提开关关闭时最后一个自提点可以删除");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			deletecollectiongoodsaddressBean.setAddressId(addressId);
			deletecollectiongoodsaddressBean.setSellerId(mchId_channl);
			deletecollectiongoodsaddressCall.setData(deletecollectiongoodsaddressBean);
			deletecollectiongoodsaddressCall.callService();			
			Logger.verifyEquals("200", deletecollectiongoodsaddressCall.getString("code"), "验证code");
			CollectiongoodsAddress c = CollectionGoodsWapper.selectCollectiongoodsAddress(addressId, mchId_channl).get(0);
			Logger.verifyEquals(true, c.getDeleted(), "删除");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}